package com.zygh.lz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zygh.lz.dao.VehicleCoordinateMapper;
import com.zygh.lz.entity.VehicleCoordinate;
import com.zygh.lz.service.VehicleCoordinateService;
import com.zygh.lz.util.DataTime;
import com.zygh.lz.util.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: shuaiqi
 * @CreateTime: 2022-12-26  16:34
 */
@Service
public class VehicleCoordinateServiceImpl extends ServiceImpl<VehicleCoordinateMapper, VehicleCoordinate> implements VehicleCoordinateService {

    @Resource
    private VehicleCoordinateMapper vehicleCoordinateMapper;

    /**
     * 根据车牌号码和车牌颜色查询车辆定位信息
     *
     * @param number 车牌号码
     * @param color  车牌颜色
     * @return
     */
    @Override
    public VehicleCoordinate getByNumber(String number, String color) {
        return vehicleCoordinateMapper.getByNumber(number, color);
    }

    @Override
    public void deleteVehicleCoordinate() {
        //昨天的开始时间
//        String startYesterday = DataTime.getStartDay();
        //昨天的结束时间
//        String endYesterday = DataTime.getEndDay();

        Date dNow = new Date();   //当前时间
        Date dBefore = new Date();
        Calendar calendar = Calendar.getInstance(); //得到日历
        calendar.setTime(dNow);//把当前时间赋给日历
        calendar.add(Calendar.MONTH, -3);  //设置为前3月
        dBefore = calendar.getTime();   //得到前3月的时间
        Date time = DateUtils.getEndTimeOfCurrentMonth(dBefore);
        vehicleCoordinateMapper.deleteVehicleCoordinate(time.toString());
    }
}
